<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>

<%@include file="/common/head.jsp" %>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                    	<form role="form" class="form-inline" id="query-form" method="post" action="${ctx }/admin/employee/list" >
                    		<!-- 查询开始 -->
                            <%--<div class="form-group">
                                <label for="query-user" class="sr-only2">用户ID</label>
                                	<input &lt;%&ndash;type="hidden" &ndash;%&gt;id="user-id" name="user.id" value="${query.user.id }" class="form-control">
				                 	<input type="text" class="form-control" id="user-name" name="user.id" value="${query.user.id }"
				                 		onclick="bring({
										                 	url:'${ctx}/admin/user/search',
										                 	name: 'id',
										                 	idInput: 'user-id',
										                 	nameInput: 'user-name'
										                 	})" />
                            </div>--%>
							<%--<div class="form-group">
								<label for="query-user.id" class="sr-only2">用户ID</label>
								<input type="text" id="query-user.id" name="user.id" value="${query.user.id }" class="form-control input-sm">

							</div>--%>

							<div class="form-group">
								<label for="query-user_id" class="sr-only2">员工工号</label>
								<input type="text" id="query-user_id" name="user_id" value="${query.user_id }" class="form-control input-sm">
							</div>

                            <div class="form-group">
                                <label for="query-name" class="sr-only2">姓名</label>
                                	<input type="text" id="query-name" name="name" value="${query.name }" class="form-control input-sm">
                                
                            </div>
                            <div class="form-group">
                                <label for="query-phone" class="sr-only2">联系电话</label>
                                	<input type="text" id="query-phone" name="phone" value="${query.phone }" class="form-control input-sm">
                                
                            </div>

							<div class="form-group">
                                <label for="query-status" class="sr-only2">员工状态</label>
                                	<%--<input type="text" id="status" name="status" placeholder="请输入数字"  class="form-control input-sm">--%>
								<%--select中的value:如果没有指定value值，则会提交元素中的文本信息，否则提交value中设定的值
									name属性不能乱写，要与数据库字段对应
								--%>
								<select type="text" name="status"  id="query-status" class="form-control" >
									<option value="">请选择员工状态</option>
									<option value="1" }>录用</option>
									<option value="2" }>停职</option>
								</select>
                            </div>

                            <div class="form-group">
                            	<button class="btn btn-primary btn-sm" type="submit"><i class="fa fa-search"></i>&nbsp;查询</button>
                            </div>
                            <!-- 查询结束 -->
                        </form>
                    
						<div>
							<p>
		                        <button type="button" class="btn btn-sm btn-outline btn-primary" onclick="add()"><i class="fa fa-plus"></i> 新增</button>
		                        <button type="button" class="btn btn-sm btn-outline btn-info " onclick="edit()"><i class="fa fa-paste"></i> 详情</button>
		                        <button type="button" class="btn btn-sm btn-outline btn-danger" onclick="del();">删除</button>
		                        <button type="button" class="btn btn-sm btn-outline btn-info " onclick="reOpen()"><i class="fa fa-refresh"></i> 刷新</button>
		                    </p>
						</div>
						<table id="table" data-toggle="table" data-striped="true" data-click-to-select="true" data-mobile-responsive="true">
                                    <thead>
                                        <tr>
                                            <th data-field="_state" data-checkbox="true"></th>
											<%--data-visible="false" 隐藏该列--%>
                                            <th data-field="id" data-visible="false" >员工ID</th>
                                            <%--<th data-field="user">用户ID</th>--%>
											<th data-field="user_id">员工工号</th>
                                            <th data-field="position">岗位</th>
                                            <th data-field="name">姓名</th>
                                            <th data-field="birth">出生日期</th>
                                            <th data-field="sex">性别</th>
                                            <th data-field="height">身高</th>
                                            <th data-field="weight">体重</th>
                                            <th data-field="place">籍贯</th>
                                            <th data-field="nation">民族</th>
                                            <th data-field="phone">联系电话</th>
                                            <th data-field="IDCard">身份证号</th>
                                            <th data-field="school">毕业学校</th>
                                            <th data-field="major">专业</th>
                                            <th data-field="education">学历</th>
                                            <th data-field="location">户口所在地</th>
                                            <th data-field="address">居住地址</th>
                                            <th data-field="wechat">微信号</th>
                                            <th data-field="email">邮箱</th>
                                            <th data-field="marry">婚姻状况</th>
                                            <th data-field="inTime">入职时间</th>
                                            <th data-field="status">员工状态</th>
                                        </tr>
                                    </thead>
							<tbody>
							<%--var指向当前值。varStatus可以获得与当前行数相关的一些信息如varStatus='status' 则可以用${status.index}获得当前行号。--%>
								<c:forEach items="${list}" var="n" varStatus="idx">
								<tr data-index="${idx.index }" data-id="${n.id }">
									<%--勾选框--%>
									<td class="bs-checkbox">
										<input data-index="0" name="btSelectItem" type="checkbox">
									</td>
									<td style="">${n.id }</td>
									<td style="">${n.user_id}</td>
									<%--<td style="">${n.user.id}</td>--%>
									<td style="">${n.position }</td>
									<td style="">${n.name }</td>
									<td style="">
										<fmt:formatDate value="${n.birth }" pattern="yyyy-MM-dd"/>
									</td>
									<%--性别--%>
									<td>${enum:list('Sex',n.sex )}</td>
									<td style="">${n.height }</td>
									<td style="">${n.weight }</td>
									<td style="">${n.place }</td>
									<td style="">${n.nation }</td>
									<td style="">${n.phone }</td>
									<td style="">${n.IDCard }</td>
									<td style="">${n.school }</td>
									<td style="">${n.major }</td>
									<td style="">${n.education }</td>
									<td style="">${n.location }</td>
									<td style="">${n.address }</td>
									<td style="">${n.wechat }</td>
									<td style="">${n.email }</td>
									<%--婚姻状况--%>
									<td>${enum:list('Marry', n.marry)}</td>
									<%--<td style="">${n.marry }</td>--%>
									<%--入职时间--%>
									<td style="">
										<fmt:formatDate value="${n.inTime }" pattern="yyyy-MM-dd"/>
									</td>
									<%--员工状态--%>
									<td>${enum:list('EmployeeStatus', n.status)}</td>
								</tr>
								</c:forEach>
							</tbody>
						</table>
                   
						<%@include file="/common/page.jsp" %>

					</div>
                </div>
            </div>
        </div>
    </div>
<%@include file="/common/foot.jsp" %>

<script>
	function add() {
		layer.open({
			type: 2,
			skin: 'layui-layer-rim', //加上边框
			area: [layer_big_width, layer_big_height], //宽高
			content: "${ctx}/admin/employee/detail",
			btn: ['确定', '取消'],
			yes: function(index, layero){ //或者使用btn1
				var detailForm = layer.getChildFrame('form', index);
				console.log(detailForm);
                /*员工工号必填*/
                var user_id=$('#user_id',detailForm).val();
                if (!!!user_id){alert('请输入员工工号');return false};
                var user_idReg=/^\d/;
                if(!user_idReg.test(user_id)){
                	alert("员工工号只能为数字");
                	return false;
				}
				/*姓名必填*/
				var name=$('#name',detailForm).val();
				if (!!!name){alert('请输入姓名');return false};
				/*手机号码验证*/
				var phone = $('#phone', detailForm).val();
				if(!!!phone){alert('请输入手机号码.');return false;}
				var phoneReg =/^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
				if(!phoneReg.test(phone)) {
					alert('请输入正确的手机号码.');
					return false;
				}
				/*邮箱验证*/
				var email = $('#email', detailForm).val();
				if(!!!email){alert('请输入邮箱.');return false;}
				var emailReg=/[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/;
				if(!emailReg.test(email)){
					alert('请输入正确的邮箱');
					return false;
				}
                /*身份证号码验证*/
                var iDCard = $('#iDCard', detailForm).val();
                if(!!!iDCard){alert('请输入身份证号码.');return false;}
                var iDCardReg=/^([1-6][1-9]|50)\d{4}(18|19|20)\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
                var iDCardReg2=/^([1-6][1-9]|50)\d{4}\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}$/;
                /*验证身份证日期与出生日期是否一致*/
                var idYear=iDCard.substring(6,10);
                var idMonth=iDCard.substring(10,12);
                var idDay=iDCard.substring(12,14);
                var birth=$('#birth',detailForm).val();
                var idBirth=idYear+"-"+idMonth+"-"+idDay;
                if(!iDCardReg.test(iDCard)&&!iDCardReg2.test(iDCard)){
                    alert('请输入正确的身份证号码');
                    return false;
                }
                if(birth!==idBirth){
                    alert("请核对身份证号码与出生日期是否一致");
                    return false;
                }
				detailForm.ajaxSubmit({
					success: function(data) {
						if (isSuccess(data)) {
							layer.close(index);
							reload();
						} else {
						}
					}
				});
			}, cancel: function(index){ //或者使用btn2
				//按钮【按钮二】的回调
			},
			end: function() {
				// alert('end')
			}
		});
}

function edit() {
    var selections = $('#table').bootstrapTable('getAllSelections');
	if (selections.length == 0) {
		error(k.msg.requireOne);
		return;
	}
	if (selections.length>1){
		error(k.msg.selectOnlyOne);
		return;
	}
    var id = selections[0].id;
	layer.open({
		type: 2,
		skin: 'layui-layer-rim', //加上边框
		area: [layer_big_width, layer_big_height], //宽高
		content: "${ctx}/admin/employee/detail?id="+id,
		btn: ['确定', '取消'],
		yes: function(index, layero){ //或者使用btn1
			var detailForm = layer.getChildFrame('form', index);
			console.log(detailForm);

            /*员工工号必填*/
            var user_id=$('#user_id',detailForm).val();
            if (!!!user_id){alert('请输入员工工号');return false};

			/*姓名必填*/
			var name=$('#name',detailForm).val();
			if (!!!name){alert('请输入姓名');return false};

			/*手机号码验证*/
			var phone = $('#phone', detailForm).val();
			if(!!!phone){alert('请输入手机号码.');return false;}
			var phoneReg = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
			if(!phoneReg.test(phone)) {
				alert('请输入正确的手机号码.');
				return false;
			}

			/*邮箱验证*/
			var email = $('#email', detailForm).val();
			if(!!!email){alert('请输入邮箱.');return false;}
			var emailReg=/[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/;
			if(!emailReg.test(email)){
				alert('请输入正确的邮箱');
				return false;
			}

			/*身份证号码验证*/
			var iDCard = $('#iDCard', detailForm).val();
			if(!!!iDCard){alert('请输入身份证号码.');return false;}
			var iDCardReg=/^([1-6][1-9]|50)\d{4}(18|19|20)\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
			var iDCardReg2=/^([1-6][1-9]|50)\d{4}\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}$/;
			/*验证身份证日期与出生日期是否一致*/
			var idYear=iDCard.substring(6,10);
			var idMonth=iDCard.substring(10,12);
			var idDay=iDCard.substring(12,14);
			var birth=$('#birth',detailForm).val();
			var idBirth=idYear+"-"+idMonth+"-"+idDay;
			if(!iDCardReg.test(iDCard)&&!iDCardReg2.test(iDCard)){
				alert('请输入正确的身份证号码');
				return false;
			}
			if(birth!==idBirth){
				alert("请核对身份证号码与出生日期是否一致");
				return false;
			}

			detailForm.ajaxSubmit({
				success: function(data) {
					if (isSuccess(data)) {
						layer.close(index);
						reload();
					} else {
					}
				}
			});
		}, cancel: function(index){ //或者使用btn2
			//按钮【按钮二】的回调
		},
		end: function() {
			// alert('end')
		}
	});
}

var page = "${page.page}";
function reload() {
	page_submit(page);
}
function del() {
    var selections = $('#table').bootstrapTable('getAllSelections');
    if (selections.length == 0) {
        error('请选择1条要删除的记录');
        return;
    }
	layer.confirm('确认要删除吗?', {icon: 3, title:'提示'}, function(index){
		var ids = new Array();
		for (var i = 0; i < selections.length; i++) {
			ids.push(selections[i].id);
		}
		$.ajax({
			url: "${ctx}/admin/employee/delete",
			data: {
				ids: ids.join(',')
			},
			success: function(data) {
				if (isSuccess(data)) {
					layer.close(index);
					reload();
				}
			}
		});
	});
}
paging('pagination', ${page.totalPages}, ${page.page});

</script>
</body>
<%--员工详情原跳转--%>
<%--k.layer.edit("${ctx}/admin/employee/detail?id="+id);--%>
</html>